<template>
  <!--数据信息-->
  <div class="panel-container no-margin">
    <el-table :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading">
      <el-table-column align="center" header-align="center" label="序号" type="index" width="50"></el-table-column>
      <el-table-column align="center" header-align="center" label="标题" prop="plan_title"></el-table-column>
      <el-table-column align="center" header-align="center" label="是否发送" prop="is_do_show" width="50"></el-table-column>
      <el-table-column align="center" fixed="right" header-align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="scope.row.is_do === 0" @click="handleSend(scope)">发送</el-button>
          <el-button size="mini" type="text" disabled v-else @click="handleSend(scope)">已发送</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { apiPlanDetail, apiSRMMsg } from '@/api/assetsDisposal'
export default {
  name: 'index',
  components: {},
  props: {
    id: String,
  },
  data() {
    return {
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      const info = { id: this.id }
      const formData = new FormData()
      for (let key in info) {
        formData.set(key, info[key])
      }
      apiPlanDetail(formData)
        .then((res) => {
          const items = res.data

          items.forEach((item) => {
            item.is_do_show = item.is_do === 1 ? '是' : '否'
          })
          this.dataList = items
          this.dataListLoading = false
        })
        .catch((e) => {
          this.dataList = []
          this.dataListLoading = false
        })
    },
    // 发送
    handleSend(scope) {
      this.$confirm(`确定要发送短信？`).then((_) => {
        this.dataListLoading = true
        const info = { id: scope.row.id }
        const formData = new FormData()
        for (let key in info) {
          formData.set(key, info[key])
        }
        apiSRMMsg(formData)
          .then((res) => {
            this.dataListLoading = false

            if (res.code !== 200) {
              return
            }
            this.$message({
              message: '操作成功！',
              type: 'success',
            })
            scope.row.is_do = 1
            scope.row.is_do_show = '是'
          })
          .catch(() => {
            this.dataListLoading = false
          })
      })
    },
  },
}
</script>

<style scoped lang="scss"></style>
